﻿using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

namespace Oliver.Controls
{
    public class BaseControl : UserControl
    {

        private double _myWidth;
        [Category(Defaults.CategoryName)]
        public double MyWidth
        {
            get { return _myWidth; }
            set { _myWidth = value; }
        }

        private double _myHeight;
        [Category(Defaults.CategoryName)]
        public double MyHeight
        {
            get { return _myHeight; }
            set { _myHeight = value; }
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            // Finale Size
            if (!double.IsInfinity(finalSize.Height) & !double.IsNaN(finalSize.Height))
            {
                _myHeight = finalSize.Height;
            }
            // DesiredSize
            else if (double.IsInfinity(this.Height) || double.IsNaN(this.Height))
            {
                _myHeight = this.DesiredSize.Height;
            }
            else
            {
                _myHeight = this.Height;
            }

            // Finale Size
            if (!double.IsInfinity(finalSize.Width) & !double.IsNaN(finalSize.Width))
            {
                _myWidth = finalSize.Width;
            }
            // DesiredSize
            else if (double.IsInfinity(this.Width) || double.IsNaN(this.Width))
            {
                _myWidth = this.DesiredSize.Width;
            }
            else
            {
                _myWidth = this.Width;
            }

            return base.ArrangeOverride(finalSize);
        }
    }
}
